package cn.hlife.com.hlfhaemocyte.systemsetting.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cn.hlife.com.hlfhaemocyte.MainActivity;
import cn.hlife.com.hlfhaemocyte.R;
import cn.hlife.com.hlfhaemocyte.notify.Transporter;
import cn.hlife.com.hlfhaemocyte.notify.Watcher;
import cn.hlife.com.hlfhaemocyte.utils.FragmentUtils;
import cn.hlife.com.hlfhaemocyte.utils.LogUtils;

/**
 * Created by Administrator on 2017/7/10.
 */

public class SettingFragment extends Fragment  implements View.OnClickListener,Watcher{

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
        View  view=inflater.inflate(R.layout.setting_fragment,container,false);
        view.findViewById(R.id.sx_layout).setOnClickListener(this);
        view.findViewById(R.id.wh_layout).setOnClickListener(this);
        view.findViewById(R.id.mac_layout).setOnClickListener(this);
        view.findViewById(R.id.reference_layout).setOnClickListener(this);
        view.findViewById(R.id.close_layout).setOnClickListener(this);
        view.findViewById(R.id.char_layout).setOnClickListener(this);
        view.findViewById(R.id.char2_layout).setOnClickListener(this);
        ((MainActivity)getActivity()).middleText.setText("系统设置");
        ((MainActivity)getActivity()).rightText.setVisibility(View.GONE);
        ((MainActivity)getActivity()).returnImageView.setVisibility(View.GONE);

        return view;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!hidden){
            ((MainActivity) getActivity()).middleText.setText("系统设置");
            ((MainActivity) getActivity()).rightText.setVisibility(View.GONE);
            ((MainActivity)getActivity()).returnImageView.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        int  viewID=v.getId();
        switch (viewID){
            case R.id.sx_layout:
                ((MainActivity)getActivity()).currentFragment = FragmentUtils.replaceFragment(getFragmentManager(), R.id.fragment_content,
                        CoefficientSetting.class, null,false);

                break;
            case R.id.wh_layout:
                ((MainActivity)getActivity()).currentFragment = FragmentUtils.switchFragment(getFragmentManager(), R.id.fragment_content,
                        ((MainActivity)getActivity()).getCurrnetFragment(), MaintainSetting.class, null);
                break;
            case R.id.mac_layout:
                ((MainActivity)getActivity()).currentFragment = FragmentUtils.switchFragment(getFragmentManager(), R.id.fragment_content,
                        ((MainActivity)getActivity()).getCurrnetFragment(), MacSetting.class, null);
                break;
            case R.id.close_layout:

              ((MainActivity)getActivity()).writeCommand(new byte[]{(byte) 0xaa, 0x03, 0x09, 0x06, 0x01});
                break;
//            case R.id.print_layout:
//                currentFragment = FragmentUtils.switchFragment(getFragmentManager(), R.id.fragment_content, currentFragment, MeasureFragment.class, null);

//                break;
            case R.id.char_layout:
                ((MainActivity)getActivity()).currentFragment = FragmentUtils.switchFragment(getFragmentManager(), R.id.fragment_content,
                        ((MainActivity)getActivity()).getCurrnetFragment(), CharSetting.class, null);
                break;
            case R.id.reference_layout:
                ((MainActivity)getActivity()).currentFragment = FragmentUtils.switchFragment(getFragmentManager(), R.id.fragment_content,
                        ((MainActivity)getActivity()).getCurrnetFragment(), ReportReferenceSetting.class, null);
                break;
            case R.id.char2_layout:
                ((MainActivity)getActivity()).currentFragment = FragmentUtils.switchFragment(getFragmentManager(), R.id.fragment_content,
                        ((MainActivity)getActivity()).getCurrnetFragment(), Char2Setting.class, null);
                break;
        }
    }

    @Override
    public void update(String mac, boolean isState) {
        LogUtils.e("SettingFragment--->");
    }
}
